<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Menu_builder
{
    /**
     * CodeIgniter global
     *
     * @var string
     **/
    protected $ci;

    /**
     *
     */
    public function __construct()
    {
        $this->ci =& get_instance();

        $this->ci->load->model('navigation/navigation_model');
    }

    public function getMenuHtml($id, $menu_name)
    {
        $items = array();
        $rows = $this->ci->navigation_model->getMenuItemsFor($id);

        foreach ($rows as $row)
        {
            $items[] = anchor($row->uri, $row->title);
        }

        return ul( $items, array('class'=> 'menu-'.$menu_name) );
    }

    /**
     *
     */
    public function loadMenus()
    {
        $menus = array();
        $rows = $this->ci->navigation_model->getAll();

        foreach ($rows as $row)
        {
            $menus[$row->name] = $this->getMenuHtml($row->id, $row->name);
        }

        $this->ci->load->vars(array('menus'=>$menus));
    }

}